﻿Imports System.Data.SQLite
Imports Sunts.DataLayer.SQLite

Public Class BackupRecurrenceType
    Public Property BackupRecurrenceTypeID As Int32
    Public Property BackupRecurrenceType As String
    Public Property FriendlyName As String

    Public Enum BackupRecurrence
        SingleBackup = 1
        WeeklyBackup = 2
        DailyBackup = 3
    End Enum

    Public Shared Function SelectAll(ConnectionString As String) As BackupRecurrenceTypeCollection
        Dim BackupRecurrenceTypeCollection As BackupRecurrenceTypeCollection
        Dim BackupRecurrenceType As BackupRecurrenceType
        Dim Reader As SQLiteDataReader

        Try
            Using sdl As New SQLiteDataLayer(ConnectionString)
                sdl.CommandText = "SELECT BackupRecurrenceTypeID, BackupRecurrenceType, FriendlyName FROM BackupRecurrenceType"

                BackupRecurrenceTypeCollection = New BackupRecurrenceTypeCollection

                Reader = sdl.ExecuteDataReader

                While Reader.Read
                    BackupRecurrenceType = New BackupRecurrenceType
                    BackupRecurrenceType.BackupRecurrenceTypeID = CInt(Reader("BackupRecurrenceTypeID"))
                    BackupRecurrenceType.BackupRecurrenceType = CStr(Reader("BackupRecurrenceType"))
                    BackupRecurrenceType.FriendlyName = CStr(Reader("FriendlyName"))
                    BackupRecurrenceTypeCollection.Add(BackupRecurrenceType)
                End While
                Reader.Close()
            End Using

            SelectAll = BackupRecurrenceTypeCollection

        Catch ex As Exception
            Throw New Exception("BackupRecurrenceType: SelectAll()" + ControlChars.CrLf + ex.Message + " " + ex.Source + ex.StackTrace)
        Finally
            BackupRecurrenceType = Nothing
            BackupRecurrenceTypeCollection = Nothing
            Reader = Nothing
        End Try
    End Function
End Class

Public Class BackupRecurrenceTypeCollection
    Inherits System.Collections.ObjectModel.Collection(Of BackupRecurrenceType)
End Class